package situ.autoweter.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sun.javafx.collections.MappingChange;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import situ.autoweter.entity.SyEmp;
import situ.autoweter.service.RdChangevalueService;
import situ.autoweter.entity.RdChangevalue;
import situ.autoweter.tools.GetFileItemlsForMVC;

import javax.servlet.http.HttpServletRequest;
import java.beans.PropertyEditor;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
/**
 * RdChangevalue的路由接口服务
 * 
 * @author 胡文
 *
 */
@Controller
public class RdChangevalueController {

	/** RdChangevalueService服务 */
	@Autowired
	private RdChangevalueService rdChangevalueService;
	
	/**
	 * 查询所有RdChangevalue数据的方法
	 * @param value
	 * @return
	 */
	@RequestMapping(value = "queryRdChangevalue", produces = {"application/json;charset=UTF-8"})
	public String find(RdChangevalue value,Map map) {
		 List<RdChangevalue> list= rdChangevalueService.find(value);
         map.put("items",list);
         return "页面名称自己改";
	}
	
	/**
	 * 通过id查询RdChangevalue数据的方法
	 * 
	 * @return
	 */
	@RequestMapping(value = "queryRdChangevalueById/{id}", produces = {"application/json;charset=UTF-8"})
	public String findOne(@PathVariable(name="id") Object id,Map map) {
        RdChangevalue obj=  rdChangevalueService.findOne(id);
        map.put("RdChangevalue",obj);
        return "页面名称自己改";
	}
	
	/**
	 * 插入RdChangevalue属性不为空的数据方法
	 * 
	 * @return
	 */
	@RequestMapping(value = "saveRdChangevalue", produces = {"application/json;charset=UTF-8"})
	public String save(RdChangevalue value) {
		  rdChangevalueService.saveNotNull(value);
        return "redirect:/queryRdChangevalue";
	}
	
	/**
	 * 更新RdChangevalue属性不为空的数据方法
	 * 
	 * @return
	 */
	@RequestMapping(value = "updateRdChangevalue", produces = {"application/json;charset=UTF-8"})
	public String update(RdChangevalue value) {
		  rdChangevalueService.updateNotNullById(value);
          return "redirect:/queryRdChangevalue";
	}
	
	/**
	 * 通过id删除RdChangevalue数据方法
	 * 
	 * @return
	 */
	@RequestMapping(value = "delRdChangevalueById/{id}", produces = {"application/json;charset=UTF-8"})
	public String delete(@PathVariable(name="id") Object id) {
		  rdChangevalueService.deleteById(id);
          return "redirect:/queryRdChangevalue";
	}
	/**
	 * @author 汪亮
	 * 根据多表连接加分页查询相关数据
	 *
	 */
	@RequestMapping("rd_reportCPreAmount.html")
  public String Pagequery(Map map,
       @RequestParam(defaultValue ="1",required = false) int startPage ,
       @RequestParam(defaultValue = "5",required = false) int PageSize){
        PageHelper.startPage(startPage, PageSize);
        List<Map> list = rdChangevalueService.Pagequery(); //我们的查询全部 被夹在中间就可以分页了
        PageInfo pageInfo = new PageInfo<Map>(list,5);
        List<SyEmp>emps=rdChangevalueService.findemp();
        map.put("pageInfo", pageInfo);
        map.put("startPage", startPage);
        map.put("PageSize", PageSize);
         map.put("emps", emps);
        map.put("list", list);

  	    return "page/rd_reportCPreAmount.html";
  }

@RequestMapping("/gjquery")
  public String gjquery(Map map,
	RdChangevalue rdChangevalue,
	@RequestParam(defaultValue ="1",required = false) int startPage ,
	@RequestParam(defaultValue = "5",required = false) int PageSize
                        ){
	PageHelper.startPage(startPage, PageSize);
	List<Map>list=rdChangevalueService.gjquery(rdChangevalue);
	PageInfo pageInfo = new PageInfo<Map>(list,5);
	List<SyEmp>emps=rdChangevalueService.findemp();
	map.put("pageInfo", pageInfo);
	map.put("startPage", startPage);
	map.put("PageSize", PageSize);
	map.put("emps", emps);
	map.put("list", list);
	map.put("EmpID", rdChangevalue.getEmpID());
	map.put("date1",rdChangevalue.getDate1() );
	map.put("date2",rdChangevalue.getDate2() );
	    return "page/rd_reportCPreAmount.html";
  }
	@InitBinder  //
	public void dateconvert(WebDataBinder bind){
		DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		PropertyEditor n=new CustomDateEditor(format, true);
		bind.registerCustomEditor(Date.class, n);
	}




}

